package com.zzyl.nursing.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.*;
import com.zzyl.nursing.dto.FamilyMsgDto;
import com.zzyl.nursing.dto.PageClass;
import com.zzyl.nursing.dto.questDto;
import com.zzyl.nursing.vo.ElderMsgVo;
import com.zzyl.nursing.vo.MemberVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 客户老人关联Controller
 * 
 * @author alexis
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "客户老人关联管理")
public class FamilyMemberElderController extends BaseController
{
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    /**
     * 查询客户老人关联列表
     */
    @PreAuthorize("@ss.hasPermi('member:user:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取客户老人关联列表")
    public TableDataInfo<List<FamilyMemberElder>> list(@ApiParam(value = "客户老人关联查询条件") FamilyMemberElder familyMemberElder)
    {
        startPage();
        List<FamilyMemberElder> list = familyMemberElderService.selectFamilyMemberElderList(familyMemberElder);
        return getDataTable(list);
    }

    /**
     * 导出客户老人关联列表
     */
    @PreAuthorize("@ss.hasPermi('member:user:export')")
    @Log(title = "客户老人关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出客户老人关联列表")
    public void export(HttpServletResponse response, @ApiParam(value = "客户老人关联查询条件") FamilyMemberElder familyMemberElder)
    {
        List<FamilyMemberElder> list = familyMemberElderService.selectFamilyMemberElderList(familyMemberElder);
        ExcelUtil<FamilyMemberElder> util = new ExcelUtil<FamilyMemberElder>(FamilyMemberElder.class);
        util.exportExcel(response, list, "客户老人关联数据");
    }

    /**
     * 获取客户老人关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:user:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取客户老人关联详细信息")
    public R<FamilyMemberElder> getInfo(@ApiParam(value = "客户老人关联ID", required = true) @PathVariable("id") Long id)
    {
        return R.ok(familyMemberElderService.selectFamilyMemberElderById(id));
    }

    /**
     * 新增客户老人关联
     */
    @PreAuthorize("@ss.hasPermi('member:user:add')")
    @Log(title = "客户老人关联", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增客户老人关联")
    public AjaxResult add(@ApiParam(value = "客户老人关联实体", required = true) @RequestBody FamilyMemberElder familyMemberElder)
    {
        return toAjax(familyMemberElderService.insertFamilyMemberElder(familyMemberElder));
    }

    /**
     * 修改客户老人关联
     */
    @PreAuthorize("@ss.hasPermi('member:user:edit')")
    @Log(title = "客户老人关联", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改客户老人关联")
    public AjaxResult edit(@ApiParam(value = "客户老人关联实体", required = true) @RequestBody FamilyMemberElder familyMemberElder)
    {
        return toAjax(familyMemberElderService.updateFamilyMemberElder(familyMemberElder));
    }

    /**
     * 删除客户老人关联
     */
    @PreAuthorize("@ss.hasPermi('member:user:remove')")
    @Log(title = "客户老人关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除客户老人关联")
    public AjaxResult remove(@ApiParam(value = "客户老人关联ID数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(familyMemberElderService.deleteFamilyMemberElderByIds(ids));
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody FamilyMsgDto dto){
        familyMemberElderService.add(dto);
        return success();
    }

    @GetMapping("/my")
    public R<List<MemberVo>>  lookMember(){
       List<MemberVo> list= familyMemberElderService.selectAll();
        return R.ok(list);

    }


    @GetMapping("/list-by-page")
    public R<List<ElderMsgVo>> listByPage(PageClass pageClass){

      List<ElderMsgVo> list=  familyMemberElderService.selectElder(pageClass);

        return R.ok(list);


    }

    @PostMapping("/QueryDevicePropertyStatus")
    public R<groupOfDevice> devicePropertyStatus(@RequestBody questDto request){
       statusD l= familyMemberElderService.selectDevice(request);
        groupOfDevice groupOfDevice = new groupOfDevice(l);


        return R.ok(groupOfDevice);

    }

    @GetMapping("/queryDeviceDataListByDay")
    public R<List<TimeOfData>> query(@RequestParam String functionId,
            @RequestParam Long startTime,
            @RequestParam Long endTime,
            @RequestParam String iotId){

      List<TimeOfData> list=  familyMemberElderService.queryDataOfTime(functionId,startTime,endTime,iotId);

      return R.ok(list);


    }


    @GetMapping("/queryDeviceDataListByWeek")
    public R<List<TimeOfData>>queryDeviceDataListByWeek(@RequestParam String functionId,
            @RequestParam Long startTime,
            @RequestParam Long endTime,
            @RequestParam String iotId){

      List<TimeOfData> list=  familyMemberElderService.queryDataOfWeek(functionId,startTime,endTime,iotId);

      return R.ok(list);


    }



}
